package com.wxgy.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.wxgy.entity.User;
import com.wxgy.service.IUserService;
import com.wxgy.service.UserService;
import com.wxgy.service.impl.UserServiceImpl;

/**
 * Servlet implementation class LoginClServlet
 */
@WebServlet("/LoginClServlet")
public class LoginClServlet extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//response.getWriter().append("Served at: ").append(request.getContextPath());

		  String username=request.getParameter("username");
		  String passwd=request.getParameter("password");
		  
		  User user=new User();
		    user.setUsername(username);
			user.setPasswd(passwd);
			
//			UserService us=new UserService();
			IUserService us=new UserServiceImpl();
		    boolean flag=us.queryUser(user);
		  
		  if(flag){
			  //index.jsp
			  HttpSession session=request.getSession();
			  session.setAttribute("username",username );
			  
//			  List list=us.queryAllUser();
			 
//			  request.setAttribute("list", list);
//			  request.getRequestDispatcher("index.jsp").forward(request, response);
			  request.getRequestDispatcher("QueryUserByPageNowServlet").forward(request, response);
		  }else{
			 // login.jsp
			 response.sendRedirect("login.jsp");
		  }
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doGet(request, response);
	}

}
